package com.atguigu.exam;

import java.io.*;
import java.util.Scanner;

/**
 * 使用输入流读取试题文件，每次显示试题文件中的一道题目。
 * 读取到字符“*”时暂停读取，等待用户从键盘输入答案。
 * 用户做完全部题目后。程序给出用户的得分。
 *
 * @author xbd
 * @create 2021-05-31 0:20
 */
public class AnswerTest {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        File file = new File("123.txt");
        String s, ans = "ABCD";
        int score = 0;
        StringBuffer result = new StringBuffer();
        try {
            FileReader r = new FileReader(file);
            BufferedReader br = new BufferedReader(r);
            while ((s = br.readLine()) != null) {
                if (!s.startsWith("*")) {
                    System.out.println(s);
                } else {
                    System.out.println("Please input your answer");
                    result.append(scan.next().charAt(0));
                }
            }
            br.close();
        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        for (int i = 0; i < result.length(); i++) {
            if (Character.toUpperCase(result.charAt(i)) == ans.charAt(i))
                score += 25;
        }
        System.out.println("Final score is " + score);
    }
}
